document.getElementById('example').addEventListener('click', function() {
    document.getElementById('input1_3').value = 'hsa-miR-410-5p'; // 自动填充输入框内容
});
document.getElementById('resetsearch').addEventListener('click', function() {
    document.getElementById('input1_3').value = ''; // 清空输入框内容
    $('#input1_3').focus();
});

$(".submit_mir").click(function (){
    var flag = $("#input1_1").val();
    var mir = $("#input1_3").val();
    $.ajax({
        url: '/mircards/search',
        type: 'post',
        data:{
            "mir": mir,
            "flag": flag,
        },
        success: function(res){
            console.log(res);
            if(res[0]['num']){
                $("#res_content").css("display", "block");
                var html_str = "";
                html_str += "<div class=\"card border-success mb-3\" style=\"max-width: 80rem;\"><div class=\"card-header border-success\">Precursor "
                    +res[0]['pre_mir']+"</div><div class=\"card-body\"><div class=\"row\"><div class=\"col-2\"><h5 class=\"card-title\">Accession</h5></div>" +
                    "<div class=\"col-4\">"+"MI0000060"+"</div><div class=\"col-2\"><h5 class=\"card-title\">Family</h5></div><div class=\"col-3\">"
                    +res[0]['pre_fam']+"</div></div><div class=\"row\"><div class=\"col-2\"><h5 class=\"card-title\">Description</h5></div><div class=\"col-4\"><p class=\"card-text\">Homo sapiens"
                    +res[0]['pre_mir']+" precursor miRNA</p></div><div class=\"col-2\"><h5 class=\"card-title\">Genome context</h5></div><div class=\"col-3\">"
                    +res[0]['pre_chrom']+"</div></div><div class=\"row\"><div class=\"col-2\"><h5 class=\"card-title\">Sequence</h5></div><div class=\"col-10\"><p class=\"card-text\">"
                    +res[0]['pre_seq']+"</p></div></div></div><div class=\"row\"><div class=\"col-sm-6 mb-3 mb-sm-0\"><div class=\"card\"><div class=\"card-header\">Mature "
                    +res[0]['ma1_id']+"</div><div class=\"card-body\"><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Accession</h6></div><div class=\"col-6\">"
                    +res[0]['ma1_acc']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Sequence</h6></div><div class=\"col-8\">"
                    +res[0]['ma1_seq']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Genome context</h6></div><div class=\"col-8\">"
                    +res[0]['ma1_chr']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Predicted targets</h6></div><div class=\"col-4\">"
                    +"<a href=\"https://www.targetscan.org/cgi-bin/targetscan/vert_71/targetscan.cgi?mirg="+res[0]['ma1_id']+"\"><img src=\"/static/mircards/image/targetscanvert_logo.png\" class=\"card-img-top\"></a></div>"
                    +"<div class=\"col-4\"><a href=\"https://www.isical.ac.in/~bioinfo_miu/final_html_targetminer/"+res[0]['ma1_id']+"\"><img src=\"/static/mircards/image/targetminer_logo.png\" class=\"card-img-top\"></a></div>"
                    +"</div></div></div></div><div class=\"col-sm-6\"><div class=\"card\"><div class=\"card-header\">Mature "+res[0]['ma2_id']+"</div><div class=\"card-body\"><div class=\"row\">"
                    +"<div class=\"col-4\"><h6 class=\"card-title\">Accession</h6></div><div class=\"col-6\">"+res[0]['ma2_acc']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Sequence</h6></div>"
                    +"<div class=\"col-8\">"+res[0]['ma2_seq']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Genome context</h6></div>"
                    +"<div class=\"col-8\">"+res[0]['ma2_chr']+"</div></div><div class=\"row\"><div class=\"col-4\"><h6 class=\"card-title\">Predicted targets</h6></div><div class=\"col-4\">"
                    +"<a href=\"https://www.targetscan.org/cgi-bin/targetscan/vert_71/targetscan.cgi?mirg="+res[0]['ma2_id']+"\"><img src=\"/static/mircards/image/targetscanvert_logo.png\" class=\"card-img-top\"></a></div>"
                    +"<div class=\"col-4\"><a href=\"https://www.isical.ac.in/~bioinfo_miu/final_html_targetminer/"+res[0]['ma2_id']+"\"><img src=\"/static/mircards/image/targetminer_logo.png\" class=\"card-img-top\"></a></div>"
                    +"</div></div></div></div></div></div>";
                var dt = document.getElementById('res_content');
                dt.innerHTML = html_str;
            }

        }
    });
});

$(function () {
    $.ajax({
        url: '/mircards/browse',
        type: 'post',
        data:{},
        success:function(res){
            console.log(res);
        }
    });
    var node_list = [{
                    icon: "fa fa-inbox fa-fw",
                    text: "111"
                },
                {
                    icon: "fa fa-inbox fa-fw",
                    text: "222"
                }];
    var json = [
        {
            text: "miRNA List",
            icon: "fa fa-inbox fa-fw",
            nodes: [
                {
                    text: "Mature miRNA",
                    icon: "fa fa-inbox fa-fw",
                    nodes: node_list,
                },
                {
                    icon: "fa fa-inbox fa-fw",
                    text: "Precursor miRNA",
                    nodes:[
                        {
                            icon: "fa fa-inbox fa-fw",
                            text: "3"
                        },
                    ],
                }
            ],
            expanded:true,
        },
        // {
        //     icon: "fa fa-globe fa-fw",
        //     text: "Go to Google",
        //     class: "text-info",
        //     href: "https://google.com"
        // }
    ];
    $('#tree').bstreeview({
        data: json,
        expandIcon: 'fa fa-angle-down fa-fw',
        collapseIcon: 'fa fa-angle-right fa-fw',
        indent: 1.25,
        expanded: true,
        parentsMarginLeft: '1.25rem',
        openNodeLinkOnNewTab: false,

    });
});